package install

import (
	"trader/config"
	"trader/models"
	"trader/store"
)

var tables = make([]any, 0)

func Migrate(configFile string) {
	tables = []any{
		// User
		new(models.User),
		new(models.UserExtend),
		new(models.Role),
		new(models.Permission),
		new(models.UserRole),
		new(models.RolePermission),
		new(models.ApiResource),
		new(models.PermissionApi),
		// Note
		new(models.TradingAccount),
		new(models.Stock),
		new(models.TransactionPlan),
		new(models.TransactionRecord),
	}

	configInst := config.NewConfig(configFile)
	engine := store.ConnectMysql(configInst.Mysql)
	err := engine.Sync(tables...)
	if err != nil {
		panic(err)
	}
}
